package util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import net.sf.struts.saif.ActionHaveForwardInterceptor;

/*
 * 功能:判断是否登录的拦截器
 * 
 */
public class loginInterceptor implements ActionHaveForwardInterceptor{

	 public ActionForward afterAction(Action arg0, ActionMapping arg1,
             ActionForm arg2, HttpServletRequest arg3, HttpServletResponse arg4)
            throws IOException, ServletException {
        // TODO Auto-generated method stub
        return null;
     }

    public ActionForward beforeAction(Action action, ActionMapping mapping,
             ActionForm form, HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
    	if(request.getSession().getAttribute("user")==null||request.getSession().getAttribute("user").equals("")){
			//登陆失败;
			return mapping.findForward("loginError");
		}
        return null;
     }
	
}